<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'phone','account', 'password','type','companyId', 'api_token',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function generateToken()
    {
       $this->api_token = str_random(60);
       $this->save();

       return $this->api_token;
    }
    public function cominfo(){
        return $this->belongsTo('App\Model\Company','companyId','id');
    }
    public function resident(){
        return $this->hasOne('App\Model\Resident','user_id','id');
    }
    public function company()
    {
        return $this->belongsTo('App\Model\Company','companyId');
    }
    // 社区管理员的角色
    public function roles(){
        return $this->hasMany('App\Model\AdminUserRoleRelation','user_id','id');
    }
    public function menus(){
        return $this->hasMany('App\Model\AdminUserMenuRelation','user_id','id');
    }
    public function menus2(){
        return $this->hasMany('App\Model\AdminUserMenuMRelation','user_id','id');
    }
}
